const express = require('express');
// 提问
const router = express.Router();
// 配置二级路由

// http://localhost:3000/api/getmsg

router.get('/getmsg', (req, res) => {
    res.send(200, 'getmsg获取成功');
});
// http://localhost:3000/api/postmsg
router.post('/postmsg', (req, res) => {
    console.log(req.body);
    res.send(200, req.body);
});
// promisedata
router.get('/promisedata1', (req, res) => {
    res.send(200, 'promisedata1');
});
router.get('/promisedata2', (req, res) => {
    res.send(200, 'promisedata2');
});
router.get('/promisedata3', (req, res) => {
    res.send(200, 'promisedata3');
});

// axios的请求
router.get('/getaxios1', (req, res) => {

    res.send(200, 'getaxios1成功');
});
router.get('/getaxios2', (req, res) => {
    var obj = {
        uname: 'wangqiao',
        age: 20
    }
    res.send(200, JSON.stringify(obj));
});

// getaxios3
router.get('/getaxios3', (req, res) => {
    // 做请求验证验证token是否有效
    console.log(req.headers);
    res.send(200, req.query);
});
// getaxios4  /接受参数
router.get('/getaxios4/:id', (req, res) => {
    res.send(200, req.params);
});

// postaxios1
router.post('/postaxios1', (req, res) => {
    res.send(200, req.body);
});

// deleteaxios1
router.delete('/deleteaxios1', (req, res) => {
    res.send(200, req.query);
});
// putaxios1
router.put('/putaxios1', (req, res) => {
    res.send(200, req.body);
});

// getasync1
router.get('/getasync1', (req, res) => {
    res.send(200, '张美丽');
});
// getasync2
router.get('/getasync2', (req, res) => {
    res.send(200, req.query);
});

// 暴露出去
module.exports = router;